package com.cai.servlet.page;

import com.cai.dao.UtilsDao;
import com.cai.dao.impl.UtilsDaoImpl;
import com.cai.entity.Items;
import com.cai.util.PageUtil;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

/**
 * @author RuoLi
 */
@WebServlet(name = "ServletItemPage", value = "/pageItems")
public class ServletItemPage extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        UtilsDao utilsDao=new UtilsDaoImpl();
        //一页显示数据
        int pageSize=5;
        //当前页
        int count=0;
        //接收页数
        String page = request.getParameter("page");
        count=Integer.parseInt(page);
        //数据 页数的数据
        List<Items> pageList = utilsDao.itemQueryPage(count,pageSize);
        //总数据条数
        int totalCount = utilsDao.selectAllItemsCount();
        //总页数
        int totalPage = PageUtil.showPage(totalCount,pageSize);
        request.setAttribute("totalCount_items", totalCount);
        request.setAttribute("totalPage_items", totalPage);
        request.setAttribute("pageList_items", pageList);
        request.getRequestDispatcher("product_list.jsp").forward(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
